-- @owner: @zhanghuan96
-- @date: 2024/11/5
-- @testpoint: GMS_XMLGEN.GETXMLTYPE语法2，参数个数测试，部分测试点合理报错
@conn PrimaryDbAmode;
--前置条件
drop extension if exists gms_xmlgen;
create extension gms_xmlgen;
set behavior_compat_options = 'bind_procedure_searchpath';
--step1:建表;expect:成功
drop table if exists t_getxmltype0005;
CREATE TABLE t_getxmltype0005 (
    id SERIAL PRIMARY KEY,
    binary_data BYTEA
);
INSERT INTO t_getxmltype0005 (binary_data) VALUES (E'\\xDEADBEEF');
INSERT INTO t_getxmltype0005 (binary_data) VALUES (E'\\x12345678');
select * from t_getxmltype0005;
--step2:只传入参数1，参数1是查询语句;expect:成功
DECLARE
xml_cxt gms_xmlgen.ctxhandle;
xml_type xmltype;
BEGIN
xml_type := gms_xmlgen.getxmltype('select * from t_getxmltype0005');
RAISE INFO 'INFO:XML Output: %', xml_type::text; 
gms_xmlgen.closecontext(xml_cxt);
END;
/
--step3:设置二进制在xml中已hex形式显示;expect:
set xmlbinary=hex;
--step4:执行;expect:成功
DECLARE
xml_cxt gms_xmlgen.ctxhandle;
xml_type xmltype;
BEGIN
xml_type := gms_xmlgen.getxmltype('select * from t_getxmltype0005');
RAISE INFO 'INFO:XML Output: %', xml_type::text; 
gms_xmlgen.closecontext(xml_cxt);
END;
/
--step5:入参个数为2个;expect:成功
DECLARE
xml_cxt gms_xmlgen.ctxhandle;
xml_type xmltype;
BEGIN
xml_type := gms_xmlgen.getxmltype('select * from t_getxmltype0005', 1);
RAISE INFO 'INFO:XML Output: %', xml_type::varchar2(500);
gms_xmlgen.closecontext(xml_cxt);
END;
/
--step6:无参;expect:报错
DECLARE
xml_cxt gms_xmlgen.ctxhandle;
xml_type xmltype;
BEGIN
xml_type := gms_xmlgen.getxmltype();
RAISE INFO 'INFO:XML Output: %', xml_type::text; 
gms_xmlgen.closecontext(xml_cxt);
END;
/

--step7:3个参数;expect:报错
DECLARE
xml_cxt gms_xmlgen.ctxhandle;
xml_type xmltype;
BEGIN
xml_type := gms_xmlgen.getxmltype('select * from t_getxmltype0005',0, 1);
RAISE INFO 'INFO:XML Output: %', xml_type::text; 
gms_xmlgen.closecontext(xml_cxt);
END;
/
--step8:清理环境;expect:成功
drop table t_getxmltype0005;
drop extension if exists gms_xmlgen;
